package com.ziqikeji.xianyan.entity.article;

import com.ziqikeji.xianyan.entity.category.Category;
import com.ziqikeji.xianyan.entity.tag.ArticleTag;
import com.ziqikeji.xianyan.enumeration.YesOrNoEnum;
import com.ziqikeji.xianyan.common.BaseEntity;
import org.springframework.format.annotation.DateTimeFormat;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

/**
 * 文章 entity
 * @author liuyu
 */
@Entity
@Table(name = "article")
public class Article extends BaseEntity {

    /**
     * 标题
     */
    private String title;
    /**
     * 作者
     */
    private String witter;
    /**
     * 创作时间
     */
    private Date time;
    /**
     * 内容
     */
    private String content;
    /**
     * 赞（数量）
     */
    private Long likeNumber;
    /**
     * 踩（数量）
     */
    private Long hateNumber;
    /**
     * 是否通过审核
     */
    private YesOrNoEnum isPassed;
    /**
     * 文章分类
     */
    private Category category;
    /**
     * 文章标签
     */
    private List<ArticleTag> articleTagList;

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getWitter() {
        return witter;
    }

    public void setWitter(String witter) {
        this.witter = witter;
    }

    @Temporal(TemporalType.DATE)
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    public Date getTime() {
        return time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    @Lob
    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public Long getLikeNumber() {
        return likeNumber;
    }

    public void setLikeNumber(Long likeNumber) {
        this.likeNumber = likeNumber;
    }

    public Long getHateNumber() {
        return hateNumber;
    }

    public void setHateNumber(Long hateNumber) {
        this.hateNumber = hateNumber;
    }

    @Enumerated(EnumType.STRING)
    public YesOrNoEnum getIsPassed() {
        return isPassed;
    }

    public void setIsPassed(YesOrNoEnum isPassed) {
        this.isPassed = isPassed;
    }

    @ManyToOne
    @JoinColumn(name = "category_id")
    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }

    @ManyToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinTable(name = "article_tag", joinColumns = @JoinColumn(name = "article_id"),
            inverseJoinColumns = @JoinColumn(name = "tag_id"))
    public List<ArticleTag> getArticleTagList() {
        return articleTagList;
    }

    public void setArticleTagList(List<ArticleTag> articleTagList) {
        this.articleTagList = articleTagList;
    }
}
